package com.keppardo.dyndns.reader;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

public class FreeDNSXmlReader {

	public static List<Element> domainListItems(byte[] xml) throws Exception{
		System.out.println("Read xml file from server");
		
		long begin = System.currentTimeMillis();
		XMLReader reader = XMLReaderFactory.createXMLReader();
		SAXReader sax = new SAXReader(reader);
		Document doc = sax.read(new ByteArrayInputStream(xml));
		Element root = doc.getRootElement();
		List<Element> items = root.elements();
		long end = System.currentTimeMillis();
		System.out.println("Xml read elapsing time: "+(end-begin)+"ms");
		return items;
	}
	
}
